package org.vasil.jouikov.services

import org.apache.commons.net.ftp.FTPClient

class FtpService {


// <editor-fold defaultstate="collapsed" desc="sendFroogleFTPFile()">

    def send(inputFileName, remoteFileName) {

        new FTPClient().with {

            connect "uploads.google.com"
            //connect "localhost"

            enterLocalPassiveMode()
            //println "enterLocalPassiveMode: ${replyString}"

            login "cvestfroogle", "5tgb6yhn"
            //println "login: ${replyString}"

            changeWorkingDirectory "."
            fileType = FTPClient.BINARY_FILE_TYPE
            //println "fileType: ${replyString}"

            // upload file
            def file = new File("/var/lighttpd/1.4/docroot/advert/froogle/${inputFileName}")
            file.withInputStream { fis ->
                storeFile remoteFileName, fis
            }
            // download file
            //def file = new File("/var/lighttpd/1.4/docroot/advert/froogle/${inputFileName}")
            //file.withOutputStream { ostream ->
            //    retrieveFile remoteFileName, ostream
            //}

            disconnect()
        }
    }
// </editor-fold>

}

